﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Protocol.world;
using Pixysoft.Weblications.Sango.Environment;
using Pixysoft.Weblications.Sango.Protocol;
using Pixysoft.Weblications.Sango.Constant;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Protocol.player;
using Pixysoft.Weblications.Sango.Battle;

namespace Pixysoft.Weblications.Sango.Command.world
{
    partial class SangoWorldHandler
    {
        public world_nationlist world_nationlist()
        {
            world_nationlist response = ReflectionManager.CreatePojo<world_nationlist>();

            string userCode = SangoManager.Authentication();
            Entities.Usr_Profile profile = UsrProfileDao.getUsrProfile(userCode);
            Entities.Usr_Section section = UsrSectionDao.GetSection(userCode);

            response.mynation = UsrSectionFacade.ToNation(CityNationHelper.SearchByType(section.Nationtypecode));

            List<world_nation> nations = new List<world_nation>();
            foreach (Entities.Cti_Nation orm in CityNationHelper.SearchAll())
            {
                if (orm.Nationtypecode == section.Nationtypecode)
                    continue;
                if (orm.Nationtypecode == NationTypecodeCollection.CAMP_NONE)
                    continue;

                nations.Add(UsrSectionFacade.ToNation(orm));
            }

            response.hasbattleresult = UsrSectionBattleDao.GetSectionBattlesCount(userCode) > 0;
            response.hasbattle = RvrSectionController.Instance.HasJoinSectionTeam(userCode);

            response.nations = nations;
            response.Succeed = true;
            return response;
        }
    }

    public interface world_nationlist : ISangoResponse
    {
        world_nation mynation { get;set;}
        List<world_nation> nations { get;set;}

        bool hasbattle { get;set;}
        bool hasbattleresult { get;set;}
    }
}
